package com.hrc.springbootdemo.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<MyFilter> customFilterRegistration() {
        FilterRegistrationBean<MyFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new MyFilter());
        // 设置过滤的 URL 模式
        registrationBean.addUrlPatterns("/*");
        // 设置过滤器的执行顺序
        registrationBean.setOrder(1);
        return registrationBean;
    }
}